package com.example.kotlin;

import com.aliyun.openservices.shade.org.apache.commons.lang3.StringUtils;
import com.example.domain.MallSku;
import javassist.bytecode.analysis.Executor;
import org.omg.SendingContext.RunTime;
import org.springframework.format.datetime.joda.LocalDateTimeParser;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.Month;
import java.time.format.DateTimeFormatter;
import java.time.temporal.TemporalAccessor;
import java.util.*;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.stream.Collectors;

/**
 * @program: demo
 * @description: 对比kotlin异同
 * @author: Mr.Wang
 * @create: 2019-06-18 10:50
 **/
public class demo {


    public static void main(String[] args) throws ParseException {
        LocalDateTime now = LocalDateTime.now();
        LocalDateTime localDateTime = now.minusDays(1);
        DateTimeFormatter dateTimeFormatter1 = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
        String s = "2020-01-01 10:22:22";
        LocalDateTime of = LocalDateTime.of(2020, Month.JANUARY, 01, 10, 10);
        LocalDateTime localDateTime1 = of.minusDays(1);

        System.out.println(of);
        System.out.println(localDateTime1);
    }

    public static void testThread() {
        //开启多线程
        final int SIZE = 4;
        System.out.println("多线程数: " + SIZE);

        List<String> list = new ArrayList<>();
        list.add("1");
        list.add("12");
        list.add("123");
        list.add("1234");
        list.add("12345");
        list.add("123456");
        list.add("1234567");
        list.add("12345678");
        list.add("123456789");
        list.add("1234567890");

        //创建线程池
        ExecutorService executorService = Executors.newFixedThreadPool(SIZE);
        list.forEach(str -> {
            executorService.execute(new Runnable() {
                @Override
                public void run() {
                    try {
                        Thread.sleep(5000L);
                        String name = Thread.currentThread().getName();
                        System.out.println("当前线程:" + name + ".mallUserId: " + str);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            });
        });

        executorService.shutdown();
        System.out.println("多线程执行完毕");

    }

    public static int test(int a) {
        for (int i = 0; i < 5; i++) {
            if (i == 4) {
                a = 10;
                break;
            }
        }
        return a;
    }

    public static int getMaxNumber(int a, int b) {
        if (a > b) {
            return a;
        } else {
            return b;
        }
    }

    public static void useWhen() {
        List<String> list = new ArrayList<>();
        list.add("wang");
        list.add("wangxiao");
        list.add("wangzhenpeng");
        for (String str : list) {
            switch (str.length()) {
                case 4:
                    System.out.println("王");
                case 8:
                    System.out.println("王晓");
                case 12:
                    System.out.println("王振鹏");

            }
        }
    }

}
